const Mock = require('mockjs')
const tags = ['单人火锅', '自出烤肉', '小时候的味道', '蛋糕9选1', '海鲜自助， 随便吃', '澳洲龙虾随便吃', '鸡腿堡随便吃']
const commendKeys = ['回头客', '上菜慢', '不好吃', '不用排队']
const {  list } = Mock.mock({
  "list|10": [{
    "id": "@id",
    "image": "@image(120x120, @color)",
    "title": "@ctitle",
    "tags|2-4": [{
      "name|+1": tags
    }],
    "oldPrice|50-1000": 1,
    "discount|1-9": 1,
    "sellCount|100-100000": 1,
    "bannerImages|5-10": ["@image(375x200, @color)"],
    "commendList|2-4": [{
      "title|+1": commendKeys,
      "count|10-1000": 1
    }]
  }]
})
module.exports = app => {

  app.get('/api/list', (req, res) => {
    res.send({
      code: 200,
      data: list,
      message: '获取列表成功'
    })
  })

  app.get('/api/list/:id', (req, res) => {
    const { id } = req.params;
    const item = list.find(v => v.id === id)
    if(item) {
      res.send({
        code: 200,
        data: item,
        message: '获取详情数据成功'
      })
    } else {
      res.send({
        code: 400,
        message: '商品过期或已经下架'
      })
    }
  })
}